{/* LAYOUT模板 */}
<layout name="layout"/>
{/* LAYOUT模板 */}
{/* import Js,Css */}	
<css href="__THEMES__/css/common.css"/>
<css href="__CSS__/jquery-ui.css" />
<css href="__THEMES__/css/yx.css" />
<css href="__CSS__/style.css" />
<js href="__JS__/core/jquery-ui.1.10.4.js" />
<js href="__PLUGS__/layer-v1.8.5/layer/layer.min.js" />
{/* import js,css */}


<style>
/*选中样式*/
.selected{border:2px solid #78C5FC;}
.slt_wrap {height:550px;margin-top:20px;}
.high_light{position:relative;z-index:2000;height:100px;width:150px;margin:auto;}
.high_light li{text-align:center;display:inline-block;width:20px;height:20px;background:#eee;float:left;margin-left:10px;border-radius:10px;cursor:pointer;}
.high_light .cur {background:#00A1E9;}
.row .col-lg-6{padding:0px;margin:0px;}
</style>


<form action="javascript:addToCart({$goods.goods_id})" method="post" name="ECS_FORMBUY" id="ECS_FORMBUY" >
	<div class="maindom">
		<div class="store_main">
			<div class="w_1200 mauto">
				<div class="row">
					<div class="col-lg-6">
						<div class="" id="slideWrap" style="margin-top:20px;border:1px solid #E0E0E0;padding:5px;">
							<!--<volist name="pictures" id="picture" key="k">
								<if condition="$k eq 1">
									<div class="slide_item" data-index="{$key}" style="display: block;  background-image: url(__UPLOAD__/images/{$picture.img_url});background-position:-455px -90px;"></div>
								<else/>
									<div class="slide_item" data-index="{$key}" style="display: none; background-image: url(__UPLOAD__/images/{$picture.img_url});background-position:-455px -90px;"></div>
								</if>
							</volist>-->
							
							<volist name="pictures" id="picture" key="k">
								<if condition="$k eq 1">
									<img class="slide_item" data-index="{$key}" src="__UPLOAD__/images/{$picture.img_url}" />
								<else/>
									<img class="slide_item" data-index="{$key}" style="display: none;" src="__UPLOAD__/images/{$picture.img_url}" />
								</if>
							</volist>
						</div>
					</div>
					<div class="col-lg-6">
						<div class="slt_wrap">
							<div class="slt_main" id="selectMain" style="padding-top:20px;">
								<h1 class="title">
								   <if condition="$cfg['show_goodssn']">
										{$goods.goods_name}
									</if>
								</h1>
								<div class="pro_info">
									<h2 class="price" id="price">
										<span class="older">
										</span>￥
										<span id="shop_price" class="newer" shop_price="{$goods.shop_price_formated}"  style="font-size:18px;" bak-price="{$goods.shop_price_formated}">
										</span>
									</h2>
									<div id="pro_info_cnt" class="pro_info_cnt">                        
										<!-- {* 开始循环所有可选属性 *} -->
											<volist name="specification" id="spec" key="spec_key">
											<div class="pro_info" id="pro_{$spec.attr_id}">
												<div class="cnt_hier">
													<span class="label_info">
														{$spec.name}:
													</span>									
													<!-- {* 判断属性是复选还是单选 *} -->									
													<if condition="$spec['attr_type'] eq 1">
														<if condition="$cfg['goodsattr_style'] eq 1">
															<div class="ver_wrap" id="verWrap_{$spec.attr_id}">
																<volist name="spec['values']" id="value" key="key">												
																	<a class="ver_btn first <if condition="$key eq 1">selected</if>"  
																		name="spec_{$spec.attr_id}" value="{$value.id}" id="spec_value_{$value.id}"
																		goods_id="{$goods_id}"
																		for="spec_value_{$value.id}" onclick="changePrice('{$spec.attr_id}','{$value.id}');" ><!--#属性id,所选值id#-->
																		{$value.label} 
																		<input type="radio" style="display:none;" name="spec_{$spec.attr_id}" value="{$value.id}" <if condition="$key eq 0">checked</if> onclick="changePrice()" />
																	<!--[<if condition="$value['price'] gt 0">{$lang.plus}<elseif condition="$value['price'] lt 0"/>{$lang.minus}</if> {$value.format_price}] -->
																	</a>
																</volist>
																<input type="hidden" name="spec_list" value="{$key}" />
															</div>
														<else/>								
															<select name="spec_{$spec.attr_id}" onchange="changePrice()">
																<volist name="$spec['values']" id="value" key="key">
																	<option label="{$value.label}" value="{$value.id}">
																		{$value.label} 
																		<if condition="$value['price'] gt 0">
																			{$lang.plus}
																		<elseif condition="$value['price'] lt 0"/>
																			{$lang.minus}
																		</if>
																		<if condition="$value['price'] neq 0">
																			{$value.format_price}
																		</if>
																	</option>
																</volist>
															</select>
															<input type="hidden" name="spec_list" value="{$key}" />
														</if>
													<else/>
														<volist name="$spec['values']" id="value" key="key">
															<label for="spec_value_{$value.id}">
																<input type="checkbox" name="spec_{$spec.attr_id}" value="{$value.id}" id="spec_value_{$value.id}" onclick="changePrice()" />
																{$value.label} 
																[<if condition="$value['price'] gt 0">
																	{$lang.plus}
																<elseif condition="$value['price'] lt 0"/>
																	{$lang.minus}
																</if>
																{$value.format_price}] 
															</label>
															<br/>
														</volist>
														<input type="hidden" name="spec_list" value="{$key}" />
													</if>
												</div>
											</div>
											<div class="space10" style="width:100%;height:10px;"><!--空格--></div>
											</volist>							
										<div class="clear"></div>
									</div>
								</div>					
								<div class="pro_info">
									<div class="pro_info_cnt cnt_lier">
										<span class="label_info s_label">
											数量
										</span>
										<ul class="ver_wrap">
											<li class="pro_add_wrap">
												<a href="javascript:void(0)" class="pro_minus" data-goods-id="{$goods.goods_id}">
													-
												</a>
												<input id="buy_count" class="input"  data-goods-id="{$goods.goods_id}" onblur="change_buycount(this);" style="border:none;" value="1"/>
												<a href="javascript:void(0)" class="pro_add" data-goods-id="{$goods.goods_id}" style="border-left:1px solid #a6a6a6">
													+
												</a>
											</li>
											<li class="pro_num_tip" style="display:none;">
												（限购
												<span>
													5
												</span>
												件）
											</li>
											<div style="clear:both;"></div>
										</ul>						
										<div class="clear">
										</div>
									</div>
								</div>
								<div class="pro_info">
									<div class="pro_info_cnt cnt_bier">
										<a href="javascript: void(0)" class="bug_btn" id="buyBtn">
											立即购买
										</a>
										<a href="javascript: void(0)" class="add_btn set_mrg" id="addBtn">
											加入购物车
										</a>
									</div>
									
									<div class="pro_desc" id="errorTip" style="display: none;">
										库存不足
									</div>
									<div class="pro_desc gift_info"></div>
									<div class="pro_desc" id="fittingText"></div>
								</div>
							</div>
						</div>
					</div>					
				</div>
			</div>
						
			<ul class="high_light" id="highLight">
				<volist name="pictures" id="picture">
					<if condition="$key eq 0">
						<li class="cur" data-index="{$key}" style="display: list-item;"></li>
					<else/>
						<li data-index="{$key}" style="display: list-item;"></li>
					</if>
				</volist>
			</ul>
		</div>
		
		<!--技术参数-->
		<div class="store_detail " STYLE="display:block;">
			<include file="Goods:goods_desc"/>
		</div>
		<div class="store_detail " STYLE="display:none;">
			fsfsfsaf
		</div>
		<!--技术参数-->
	</div>
</form>



<script>
	/*改变购买数量*/
	/*加*/
	$('.pro_add').click(function(){
		var shop_price	=	parseInt($('#shop_price').attr('shop_price'));
		var count		=	parseInt($('#buy_count').val()) + 1;							
		$('#buy_count').val(count);
		$('#shop_price').text(count * shop_price);
		//changePrice('','');
	});
	/*减*/
	$('.pro_minus').click(function(){
		var shop_price	=	parseInt($('#shop_price').attr('shop_price'));
		var count		=	parseInt($('#buy_count').val()) - 1;	
		if(count == 1 || count < 1){
			$('#buy_count').val('1');
			$('#shop_price').text(1 * shop_price);
			return;
		}
		else{
			$('#buy_count').val(count);
			$('#shop_price').text(count * shop_price);
		}								
	});	
	/*改变购买数量*/
	function change_buycount(obj){
		var count	 	=	parseInt(obj.value);
		var shop_price	=	parseInt($('#shop_price').attr('shop_price'));
		/*判断是否小于0*/
		if(count < 1 || count == 1){
			$('#buy_count').val('1');
			$('#shop_price').text(1 * shop_price);
			return;
		}
		else{
			$('#buy_count').val(count);
			$('#shop_price').text(count * shop_price);
		}
	}							
</script>

<script>
	/*切换产品照片*/
	$('.high_light').find('li').each(function(n){
		$(this).click(function(){
			var index_num = $(this).attr('data-index');
			var	_this	  = $(this);
			/*显示选择的照片*/
			$('.slide_item').each(function(m){
				if(m == index_num){
					$(this).css('display','block');
				}
				else{
					$(this).css('display','none');
				}
			});
			/*改变切换按钮*/
			$('.high_light').find('li').each(function(j){
				if(j==index_num){
					$(this).addClass('cur');
				}
				else{
					$(this).removeClass('cur');
				}
			});
		});
	});
</script>

<script type="text/javascript">
	function $id(element) {
		return document.getElementById(element);
	}
	//切屏--是按钮，_v是内容平台，_h是内容库
	function reg(str){
		var bt			=	$id(str+"_b").getElementsByTagName("h2");
		for(var i=0;i<bt.length;i++){
			bt[i].subj	=	str;
			bt[i].pai	=	i;
			bt[i].style.cursor	=	"pointer";
			bt[i].onclick=function(){
				$id(this.subj+"_v").innerHTML	=	$id(this.subj+"_h").getElementsByTagName("blockquote")[this.pai].innerHTML;
				for(var j=0;j<$id(this.subj+"_b").getElementsByTagName("h2").length;j++){
					var _bt=$id(this.subj+"_b").getElementsByTagName("h2")[j];
					var ison	=	j	==	this.pai;
					_bt.className=(ison?"":"h2bg");
				}
			}
		}
		$id(str+"_h").className	=	"none";
		$id(str+"_v").innerHTML	=	$id(str+"_h").getElementsByTagName("blockquote")[0].innerHTML;
	}
	
	/* *
	 * 添加商品到购物车 
	 */
	function addToCart(goodsId, parentId){
		var goods        = new Object();
		var spec_arr     = new Array();
		var fittings_arr = new Array();
		var number       = 1;
		var formBuy      = document.forms['ECS_FORMBUY'];
		var quick		   = 0;

		// 检查是否有商品规格 
		if (formBuy){
				spec_arr = getSelectedAttributes(formBuy);

			if (formBuy.elements['number']){
			  number = formBuy.elements['number'].value;
			}

			quick = 1;
		}

		goods.quick    = quick;
		goods.spec     = spec_arr;
		goods.goods_id = goodsId;
		goods.number   = number;
		goods.parent   = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);
		
		//Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.tojsONString(), addToCartResponse, 'POST', 'jsON');
		$.ajax({
			url:'__URL__/add_to_cart',
			type:'post',
			dataType:'json',
			data:{goods:goods},
			beforeSend:function(){},
			success:function(msg){
				alert(msg);
			}
		});
	}

	
	/**
	 * 获得选定的商品属性
	 */
	function getSelectedAttributes(formBuy){
		var spec_arr = new Array();
		var j = 0;
		for (i = 0; i < formBuy.elements.length; i ++ ){
			var prefix = formBuy.elements[i].name.substr(0, 5);
			if (prefix == 'spec_' && (((formBuy.elements[i].type == 'radio' || formBuy.elements[i].type == 'checkbox') && formBuy.elements[i].checked) || formBuy.elements[i].tagName == 'SELECT')){
				spec_arr[j] = formBuy.elements[i].value;
				j++ ;
			}
		}
		return spec_arr;
	}
		
</script>

<script type="text/javascript">
	var goods_id = {$goods_id};
	var goodsattr_style = {$cfg.goodsattr_style};
	//var gmt_end_time = {$promote_end_time};
	var goodsId = {$goods_id};
	//var now_time = {$now_time};

	onload = function(){
		changePrice('','');
		//fixpng();
		try { onload_leftTime(); }
		catch (e) {}
	}
	
	/**
	 * 点选可选属性或改变数量时修改商品价格的函数
	 */
	function changePrice(attr_id,attr_value_id){
		/*处理a*/
		if(attr_id != '' && typeof attr_id != 'undefined'){
			$('#verWrap_'+attr_id).find('a').each(function(){
				$(this).removeClass('selected');
			});				
			/*所选值加上边框*/
			$('#spec_value_' + attr_value_id).addClass('selected');
		}		
		/*购买数量*/
		var qty 		= 	$('#buy_count').val(); 
		/*获取属性*/
		var attr		=	getSelectedAttributes();	
		var loading		=	null;
		/*ajax*/
		$.ajax({
			url:'__URL__/change_price?' + 'id=' + goodsId + '&attr=' + attr + '&number=' + qty,
			type:'get',
			dataType:'json',
			data:{},
			beforeSend:function(){
				loading	=	layer.load(0,2);
			},
			success:function(msg){
				layer.close(loading);
				$('#shop_price').text(msg.info.result);
				$('#shop_price').attr('shop_price',msg.info.result/msg.info.qty);
			}
		});
	}
		
	/*加入购物车*/
	$('#addBtn').click(function(){
		var goods        = new Object();
		var spec_arr     = new Array();
		var fittings_arr = new Array();
		var number       = $('#buy_count').val();
		var formBuy      = document.forms['ECS_FORMBUY'];
		var quick		   = 1;		
		/* 检查是否有商品规格*/
		spec_arr = getSelectedAttributes();
		
		goods.quick    = quick;
		goods.spec     = spec_arr;
		goods.goods_id = goodsId;
		goods.number   = number;
		goods.parent   = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);		
		var loading	   = null;		
		$.ajax({
			url:'__URL__/add_to_cart',
			type:'post',
			dataType:'json',
			data:{goods:goods},
			beforeSend:function(){
				//loading	=	layer.load(0,2);
			},
			success:function(msg){
				//addToCartResponse();
				if(msg.data == '1'){
					//layer.close(loading);
					/*处理不同错误*/
					var error = msg.info.error;
					switch(error){
						case 1:							
							layer.alert('商品不存在', 2);							
							break;
						case 2:/*缺货登记*/							
							window.location.href = "{:U('flow/yuyue')}";					
							break;
						case 3:
						layer.alert('商品已下架', 2);	
							break;
						case 4:
							layer.alert('商品不能单独销售', 2);	
							break;
						case 5:
							layer.alert('商品不能单独销售', 2);	
							break;
						case 6:
							layer.alert('请选择适合您的', 2);	
							break;
						default:
							/*跳转到购物车*/
							window.location.href = msg.info.url;
							break;
					}					
				}
			}
		});
	});	
	/**
	 * 获得选定的商品属性
	 */
	function getSelectedAttributes(){
		var spec_arr = new Array();
		$('#pro_info_cnt').find('a.selected').each(function(n){
			var _this = $(this);
			var value	=	_this.attr('value');
			spec_arr[n] = value;
		});
		return spec_arr;
	}	
</script>

<div class="space90" style="width:100%;height:90px;"><!--空格--></div>
<include file="Library:service"/>
<include file="Library:footer"/>




